package com.leadbank.baselbf.leadutils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.leadbank.baselbf.log.LogBus;

/**
 * @ClassName: AppInfo
 * @Description:
 * @Author: zhouzhiguo
 * @Date: 2024/5/27 15:52
 * @Version: 5.0.6
 * 上海利得金融科技集团版权所有.
 */

public class AppInfo {


    private static String TAG = AppInfo.class.getSimpleName();

    /**
     * 获取app渠道信息
     * @return
     */
    public static String getAppChannel(Context context){
        String channel = "";
        try {
            ApplicationInfo appInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(),
                            PackageManager.GET_META_DATA);
            Object msg= appInfo.metaData.get("UMENG_CHANNEL");
            channel = msg.toString();
        } catch (PackageManager.NameNotFoundException e) {
            LogBus.e(TAG,"NameNotFoundException",e);
        }
        return channel;
    }

    /**
     * 获取app版本
     * @return
     */
    public static String getAppVersionName(Context context){
        String versionName = "";
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo(
                    context.getPackageName()
                    ,PackageManager.GET_CONFIGURATIONS);
            versionName = pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            LogBus.e(TAG,"NameNotFoundException",e);
        }
        return versionName;
    }

}
